<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class index_controller extends jingjiren_controller{
	//构造不能用，仿构造，每个方法前掉一次
	private $yingpin_model;
	private function check()
	{
		$this->yingpin_model = $this->MODEL('yingpin');
		session_start();
		if(!isset($_SESSION['user']['username'])){

			$this->jingjiren_tpl("pin-login");die();
		}
	}

	function index_action(){
		$this->check();
		if(!empty($_SESSION['user'])){
			$this->home_action();
		}else{
			$this->jingjiren_tpl("pin-login");
		}
		//unset($_SESSION['user']);

	}
	function logout_action(){
		session_start();
		unset($_SESSION['user']);
		$this->check();

	}


	function login_action(){
		$yingpin_model = $this->MODEL('yingpin');
		$username = $_POST['username'];
		$password = $_POST['password'];

		//访问Java接口  地址随服务器更改--------------------------------------------------------------
		$url = "http://47.104.30.217:8080/lanlingwang/sys/phpLogin";
		$post_data = array ("username" => $username,"password" => $password);
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
		curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Content-Type: application/json',
			'Content-Length: ' . strlen(json_encode($post_data))
		));

		$output = curl_exec($ch);
		curl_close($ch);
		$output = json_decode($output,true);
		//接口访问结束------------------------------------------------------------------------------

		//var_dump($output);die;
		if($output['code'] === 0){
			//2019/4/16 替换跨库为java接口
			$agent_list = $yingpin_model->getSysUserOnce(array('username'=>$username));
//			$agent_list = $this->objlan->DB_select_once("sys_user","`username`=".$username);
			$agent = $yingpin_model->getAgentOnce($agent_list['userId']);
//			$agent = $this->objlan->DB_select_once("agent","`userInfo_id`=".$agent_list['userId'],"`id`");
			if(empty($agent_list)){
				echo json_encode(array('msg'=>"未查询到用户信息"));die();
			}
			$_SESSION['user']['username'] = $agent_list['realname'];
			$_SESSION['user']['login_name'] = $agent_list['username'];
			$_SESSION['user']['password'] = $agent_list['password'];
			$_SESSION['user']['mobile'] = $agent_list['mobile'];
			$_SESSION['user']['oss_url'] = $agent_list['ossUrl']?$agent_list['ossUrl']:"http://yingpin.oss-cn-qingdao.aliyuncs.com/default_head_portrait.png";
			//agent表经纪人id
			$_SESSION['user']['id'] = $agent['id'];
			//sys_user经纪人登陆表id
			$_SESSION['user']['user_id'] = $agent_list['userId'];
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=home','UserID'=>$agent_list['userId']));die;
		}elseif($output['code'] == 500){
			echo json_encode(array('msg'=>$output['msg']));die();
		}else{
			echo json_encode(array('msg'=>"账号密码验证失败"));die();
		}


//		echo json_encode(array('msg'=>'用户不存在！'));die();
//		if(strpos($this->config['code_web'],"前台登陆")!==false) {
//			$user = $this->objlan->DB_select_once("sys_user", "`username`='" . $username . "' and `password`='" . $password . "'");
//			if (!empty($user)) {
//				session_start();
//				$_SESSION['user'] = $user;
//				$this->jingjiren_tpl("pin-apply");
//			} else {
//				echo json_encode(array('msg' => '经纪人不存在！'));
//				die();
//			}
//		$url = "http://192.168.1.105:8081/credit/udun/udunInfo.do";
//		$post_data = array ("ydOrderId" => $data['ydOrderId']);
//		$ch = curl_init();
//
//		curl_setopt($ch, CURLOPT_URL, $url);
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//		// post数据
//		curl_setopt($ch, CURLOPT_POST, 1);
//		// post的变量
//		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
//		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
//			'Content-Type: application/json',
//			'Content-Length: ' . strlen(json_encode($post_data))
//		));
//
//		$output = curl_exec($ch);
//		curl_close($ch);
//		$output = json_decode($output,true);
//		var_dump($output);die;
		//}

	}
	/*
	 *首页
	 *  */
	function home_action(){
		$this->check();
		//开始计算home显示的数据需要
		//1、查询该经纪人有没有新增的客户（是否已沟通）
		$user_id = $_SESSION['user']['id'];
		$agent_list = $this->yingpin_model->getBusinessAll($user_id);
//		$agent_list = $this->objlan->DB_select_all("agent_business","`agent_id`=".$user_id);   //2019/4/16 替换跨库为java接口
		$contact = 0;
		$handle = 0;
		$change = 0;
		if(!empty($agent_list)){
			foreach($agent_list as $k=>$v){
				if($v['contact'] != 1){
					$contact = 1;break;
				}
			}
		}
		//2、查询入职人员有无待处理
		$job_list = $this->obj->DB_select_all("entry","`agent_id`='".$user_id."' and `entry_state`=0 order by add_time desc");
		if(!empty($job_list)){
			$handle = 1;
		}
		//3、查询消息有无经纪人变更  2019/4/16 替换跨库为java接口
		$agent_list = $this->yingpin_model->getMessageAll(array('agent_id'=>$_SESSION['user']['user_id'],'isSee'=>'0'));
//		$agent_list = $this->objlan->DB_select_all("agent_message"," `agent_id`=".$_SESSION['user']['user_id']." and `is_see`=0");
		if(!empty($agent_list)){
			$change = 1;
		}

		$this->yunset("contact", $contact);
		$this->yunset("handle", $handle);
		$this->yunset("change", $change);
		$this->jingjiren_tpl("pin-apply");
	}
	/*
	 * 我的客户
	 * */
	function myclient_action()
	{
		//qqqqqqqqqqqqqqqqqqqq
		$this->check();
		$user_id = $_SESSION['user']['id'];
		$this->yunset("type", $_GET['type']);
//		//分页处理
		$limit = 10;

//		//处理搜索条件     2019/4/16 替换跨库为java接口
		$where = array();
		if($_GET['keyword']){
			$where['searchValue'] = trim($_GET['keyword']);
		}
		$where['contact'] = '0';
		$where['agentId'] = $user_id;
		$no_num = $this->yingpin_model->getBusinessNum($where);
//		$no_sql = "SELECT count(*) as num FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id;
//		$no_num=$this->dblan->DB_query_all($no_sql);
		$this->yunset("no_num", ceil($no_num/$limit));

		$where['contact'] = '1';
		$num = $this->yingpin_model->getBusinessNum($where);
//		$sql = "SELECT count(*) as num FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`contact`=1 and a.`agent_id`=".$user_id;
//		$num=$this->dblan->DB_query_all($sql);
		$this->yunset("num", $num);
//		//为處理
//		$no_contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC",'all');
//		//已處理ll
//		$contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=1 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC",'all');
//$a = "SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=1 and a.`agent_id`=".$user_id." ORDER BY a.`handle_time` DESC";
//		$a= "SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id." ORDER BY a.create_time DESC";
		$this->yunset("keyword", $_GET['keyword']);
		if($_GET['type'] ==1){
			$this->yunset("page1", $_GET['page']);
			$this->yunset("page2", 1);
		}elseif($_GET['type'] ==2){
			$this->yunset("page1", 1);
			$this->yunset("page2", $_GET['page']);
		}else{
			$this->yunset("page1", 1);
			$this->yunset("page2", 1);
		}

//		$this->yunset("no_contact", $no_contact);
//		$this->yunset("contact", $contact);

		$this->jingjiren_tpl("pin-wdkh");
	}
	/*
	 * 我的客户详情
	 * */
	function info_action(){
		$this->check();
		$user_id = $_SESSION['user']['id'];


		$msg = "";
		//接收user_id
		if($_GET['user_id']){
			$member_id = $_GET['user_id'];
		}else{
			$msg = "未获取到用户信息！";
		}
		//判断用户属性
		$where = array();
		$where['userId'] = $member_id;
//		$where .= " and a.`enable` =1";
//		$filed = "`agent_id`,a.`user_id`,`username`,`mobile`,`realname`,b.`work_status`,`user_avatar`,a.`create_time`,`handle_state`,`handle_time`,`contact`,`source`";
//		$contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`user_id`=".$member_id);
		$contact = $this->yingpin_model->getBusinessUserOnce($where);
		if(empty($contact['realname'])){
			$contact['realname'] = "未填写真实姓名";
		}
		if(empty($contact['mobile'])){
			$contact['realname'] = "未认证手机号";
		}


		$this->yunset("contact", $contact);
		$this->yunset("page", $_GET['page']);
		$this->yunset("type", $_GET['type']);
		$this->jingjiren_tpl("pin-wdkh_info");
	}
	/*
	 * 跟踪记录
	 * */
	function track_action(){
		$this->check();

		//获取经纪人id和用户id查询经纪人输入的跟踪件记录表
		$user_id = $_SESSION['user']['id'];
		$member_id  = $_GET['user_id'];

		//查询个人信息    2019/4/16 替换跨库为java接口
//		$user = $this->objlan->DB_select_once("app_user","`user_id`=".$member_id,"`user_id`,`username`,`user_avatar`");
		$user = $this->getUser($member_id);
		//查询跟踪记录   //2019/4/16 替换跨库为java接口
		$where = array();
		$where ['agentId'] = $user_id;
		$where ['memberId'] = $member_id;
		$track = $this->yingpin_model->getTrackAll($where);
//		$track = $this->objlan->DB_select_all("agent_track",$where." order by track_time desc");


		$this->yunset("type", $_GET['type']);
		$this->yunset("user", $user);
		$this->yunset("track", $track);
		$this->jingjiren_tpl("pin-wdkh_record");
	}
	/*
	 * 跟踪信息保存
	 * */
	function track_save_action(){
		$this->check();
		//接收参数值
		$data = array();
		$data['agentId'] = $_SESSION['user']['id'];
		$data['memberId']   = $_POST['user_id'];
		$data['trackContent']  = $_POST['content'];
		$data['trackTime'] = date("Y-m-d H:i:s",time());
		$aid = $this->yingpin_model->addTrackOnce($data);
//		$aid=$this->objlan->insert_into('agent_track',$data);    //2019/4/16 替换跨库为java接口
		if($aid){
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=track&type='.$_POST['type'].'&user_id='.$_POST['user_id']));die;
		}else{
			echo json_encode(array('msg'=>'保存失败！'));die();
		}
	}
	/*
	 * 修改处理状态
	 * */
	function edit_handle_action(){
		$this->check();

//		if($_GET['state'] == "edit"){
//			if($_GET['chuli'] == 1){
//				$where = array();
//				$where['agent_id'] = $_SESSION['user']['id'];
//				$where['user_id'] = $_GET['user_id'];
//				$data = array();
//				$data['handle_state'] = 1;
//				$data['handle_msg'] = $_GET['content'];
//				$data['handle_time'] = date('Y-m-d H:i:s',time());
//				$data['contact'] = 1;
//				$data['update_time']  = date('Y-m-d H:i:s',time());
//				$uid = $this->objlan->DB_update_all("agent_business",$data,$where);
//
//				if($uid){
//					$this->info_action();
//				}
//			}
//
//		}


		$this->yunset("user_id", $_GET['user_id']);
		$this->yunset("type", $_GET['type']);
		$this->jingjiren_tpl("pin-wdkh_infoedit");
	}

	/*
	 * 处理结果保存  ajax
	 * */
	function handle_save_action(){
		$this->check();

		$where = array();
		$where['agentId'] =$_SESSION['user']['id'];
		$where['userId'] =$_POST['user_id'];
//		$data = "";    2019/4/16 替换跨库为java接口
		$data['handleState'] = "1";
		$data['handleMsg'] = $_POST['content'];
		$data['handleTime'] = date('Y-m-d H:i:s',time());
		$data['contact'] = "1";
		$data['updateTime'] = date('Y-m-d H:i:s',time());
		$uid = $this->yingpin_model->editBusinessOnce($data);
//		$uid = $this->objlan->DB_update_all("agent_business",$data,$where);

		if($uid){
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=myclient'));die;
		}else{
			echo json_encode(array('msg'=>'保存失败！'));die();
		}
	}


	/*
	 * 用户投递
	 * */
	function userdelivery_action()
	{
		//qqqqqqqqqqqqqqqqqqqq
		$this->check();
		$user_id = $_SESSION['user']['id'];
		$this->yunset("type", $_GET['type']);
//		//分页处理
		$limit = 10;

//		//未处理     2019/4/16 替换跨库为java接口
		$where = " 1";
		if($_GET['keyword']){
			$where .=" and  CONCAT(`username`,`mobile`) like '%".trim($_GET['keyword'])."%'";
		}
		$where .= " and `agent_id`=".$user_id;
		$where .= " and `handle_state`=0";
		$no_num = $this->obj->DB_select_num("entry",$where);
		$this->yunset("no_num", ceil($no_num/$limit));
		//已处理     2019/4/16 替换跨库为java接口
		$where = " 1";
		if($_GET['keyword']){
			$where .=" and  CONCAT(`username`,`mobile`) like '%".trim($_GET['keyword'])."%'";
		}
		$where .= " and `agent_id`=".$user_id;
		$where .= " and `handle_state`=1";
		$num = $this->obj->DB_select_num("entry",$where);
		$this->yunset("num", $num/$limit);

		$this->yunset("keyword", $_GET['keyword']);
		if($_GET['type'] ==1){
			$this->yunset("page1", $_GET['page']);
			$this->yunset("page2", 1);
		}elseif($_GET['type'] ==2){
			$this->yunset("page1", 1);
			$this->yunset("page2", $_GET['page']);
		}else{
			$this->yunset("page1", 1);
			$this->yunset("page2", 1);
		}

		$this->jingjiren_tpl("pin-yhtd");
	}
	//投递模块
	/*
	 * 用户投递
	 * */
//	function userdelivery_action(){
//		//qqqqqqqqqqqqqqqqqqqq
//		$this->check();
//		$user_id = $_SESSION['user']['id'];
//		$this->yunset("type", $_GET['type']);
//
//		$where = array();
//		if($_GET['keyword']){
//			$where['searchValue'] = trim($_GET['keyword']);
//		}
//		$where['agentId'] = $user_id;
////		$filed = "`agent_id`,a.`user_id`,`username`,`mobile`,`realname`,b.`work_status`,`user_avatar`";
//		//已處理 2019/4/16 替换跨库为java接口
//		$user_list = $this->yingpin_model->getBusinessUserAll($where);
////		$user_list = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC",'all');
//		$handle = array();
//		$no_handle = array();
//		if(!empty($user_list)){
//			foreach($user_list as $k=>$v){
//				$job_list = $this->obj->DB_select_all("entry","`member_id`='".$v['userId']."' order by add_time desc");
//				if(empty($job_list)){
//					unset($user_list[$k]);
//				}else{
//					foreach($job_list as $k2=>$v2){
//						if($v2['entry_state'] == 1){
//							$handle[$k] = $v;
//							$handle[$k]['toudi_id'] =  $v2['id'];
//							$handle[$k]['add_time'] =date('Y-m-d H:i:s',$v2['add_time']);
//							$handle[$k]['company_name'] = "投递 ".$v2['company_name'];
//							$handle[$k]['user_avatar'] = $v['userAvatar'];
//							$handle[$k]['user_id'] = $v['userId'];
//						}elseif($v2['entry_state'] == 0){
//							$no_handle[$k] = $v;
//							$no_handle[$k]['toudi_id'] =  $v2['id'];
//							$no_handle[$k]['add_time'] =date('Y-m-d H:i:s',$v2['add_time']);
//							$no_handle[$k]['company_name'] = "投递 ".$v2['company_name'];
//							$no_handle[$k]['user_avatar'] = $v['userAvatar'];
//							$no_handle[$k]['user_id'] = $v['userId'];
//						}
//					}
//
//				}
//
//			}
//		}
//
//
//		$this->yunset("keyword", $_GET['keyword']);
//		$this->yunset("handle", $handle);
//		$this->yunset("no_handle", $no_handle);
//		$this->jingjiren_tpl("pin-yhtd");
//	}

	/*
	 * 用户的投递列表
	 * */
	function delivery_list_action(){
		$this->check();
		$member_id = $_GET['user_id'];
		//查询个人信息   2019/4/16 替换跨库为java接口
//		$user = $this->objlan->DB_select_once("app_user","`user_id`=".$member_id,"`user_id`,`username`,`user_avatar`");
		$user = $this->getUser($member_id);
		if($_GET['type'] == 1){
			$job_list = $this->obj->DB_select_all("entry","`member_id`='".$member_id."' and `entry_state`=0 order by add_time desc");

		}elseif($_GET['type'] == 2){
			$job_list = $this->obj->DB_select_all("entry","`member_id`='".$member_id."' and `entry_state`=1 order by add_time desc");

		}
		if(!empty($job_list)){
			foreach($job_list as $k=>$v){
				$job_list[$k]['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
				$job_list[$k]['company_name'] = "投递 ".$v['company_name'];
			}
		}


		$this->yunset("user", $user);
		$this->yunset("job_list", $job_list);
		$this->yunset("type", $_GET['type']);
		$this->yunset("page", $_GET['page']);
		$this->jingjiren_tpl("pin-yhtd_list");
	}

	/*
	 *用户投递详情
	 */
	function delivery_info_action(){
		$this->check();
		$id = $_GET['delivery_id'];
		$type = $_GET['type'];

		//查询投递信息
		$job = $this->obj->DB_select_once("entry","`id`=".$id);
		//查询个人信息   2019/4/16 替换跨库为java接口
//		$user=$this->objlan->DB_select_once("app_user","`user_id`=".$job['member_id'],"`user_id`,`username`,`user_avatar`,`realname`");
		$user = $this->getUser($job['member_id']);
		$job['add_time'] = date('Y-m-d H:i:s',$job['add_time']);
		$job['username'] = $user['username'];
		$job['user_avatar'] = $user['user_avatar'];
		$job['realname'] = $user['realname']?$user['realname']:'未设置真实姓名';




		$this->yunset("job", $job);
		$this->yunset("type", $type);
		$this->yunset("page", $_GET['page']);
		$this->jingjiren_tpl("pin-yhtd_info");
	}

	/*
	 * 经纪人处理
	 */
	function delivery_handle_action(){
		$this->check();

		$this->yunset("id", $_GET['id']);
		$this->yunset("type", $_GET['type']);
		$this->jingjiren_tpl("pin-yhtd_infoedit");
	}

	/*
	 * 投递处理保存
	 */
	function delivery_save_action(){
		$this->check();
		$id = $_POST['id'];
		$agent_id = $_SESSION['user']['id'];


		$where = " 1";
		$where .=" and `id`=".$_POST['id'];

		$data = "";
		$data .= "`handle_state` = 1,";
		$data .= "`entry_state` = 1,";
		$data .= "`agent_id` =".$agent_id.",";
		$data .= "`muster_data` ='".$_POST['muster_data']."',";
		$data .= "`muster_time` ='".$_POST['muster_time']."',";
		$data .= "`muster_place` ='".$_POST['muster_place']."',";
		$data .= "`handle_time` ='".time()."',";
		$data .= "`edit_time` ='".time()."'";

		$uid = $this->obj->DB_update_all("entry",$data,$where);

		if($uid){
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=userdelivery'));die;
		}else{
			echo json_encode(array('msg'=>'保存失败！'));die();
		}


	}




	//用户入职模块
	function userentry_action(){
		$this->check();
		$user_id = $_SESSION['user']['id'];
		$this->yunset("type", $_GET['type']);

		$where = array();
		if($_GET['keyword']){
			$where['searchValue']=trim($_GET['keyword']);
		}
		$where['agent_id'] = $user_id;
//		$filed = "`agent_id`,a.`user_id`,`username`,`mobile`,`realname`,b.`work_status`,`user_avatar`";
		//查询该经纪人的下属用户        2019/4/16 替换跨库为java接口
//		$user_list = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC",'all');
		$user_list = $this->yingpin_model->getBusinessUserAll($where);
		$wait_entry = array();
		$entry = array();
		$over = array();
		if(!empty($user_list)){
			foreach($user_list as $k=>$v){
				$job_list = $this->obj->DB_select_all("entry","`member_id`='".$v['userId']."' order by add_time desc");
				if(empty($job_list)){
					unset($user_list[$k]);
				}else{
					foreach($job_list as $k2=>$v2){
						if($v2['entry_state'] == 1){
							$wait_entry[$k] = $v;
							$wait_entry[$k]['toudi_id'] =  $v2['id'];
							$wait_entry[$k]['add_time'] =date('Y-m-d H:i:s',$v2['add_time']);
							$wait_entry[$k]['company_name'] = "投递 ".$v2['company_name'];
							$wait_entry[$k]['user_avatar'] = $v['userAvatar'];
						}elseif($v2['entry_state'] == 2){
							$over[$k] = $v;
							$over[$k]['toudi_id'] =  $v2['id'];
							$over[$k]['add_time'] =date('Y-m-d H:i:s',$v2['add_time']);
							$over[$k]['company_name'] = "投递 ".$v2['company_name'];
							$over[$k]['user_avatar'] = $v['userAvatar'];
						}elseif($v2['entry_state'] == 3){
							$entry[$k] = $v;
							$entry[$k]['toudi_id'] =  $v2['id'];
							$entry[$k]['add_time'] =date('Y-m-d H:i:s',$v2['add_time']);
							$entry[$k]['company_name'] = "投递 ".$v2['company_name'];
							$entry[$k]['user_avatar'] = $v['userAvatar'];
						}
					}

				}

			}
		}


		$this->yunset("keyword", $_GET['keyword']);
		$this->yunset("wait_entry", $wait_entry);
		$this->yunset("entry", $entry);
		$this->yunset("over", $over);
		$this->jingjiren_tpl("pin-yhrz");
	}

	/*
	 * 用户列表
	 * */
	function entry_list_action(){
		$this->check();
		$member_id = $_GET['user_id'];
		//查询个人信息    2019/4/16 替换跨库为java接口
//		$user = $this->objlan->DB_select_once("app_user","`user_id`=".$member_id,"`user_id`,`username`,`user_avatar`");
		$user = $this->getUser($member_id);
		if($_GET['type'] == 1){
			$job_list = $this->obj->DB_select_all("entry","`member_id`='".$member_id."' and `entry_state`=1 order by add_time desc");

		}elseif($_GET['type'] == 2){
			$job_list = $this->obj->DB_select_all("entry","`member_id`='".$member_id."' and `entry_state`=3 order by add_time desc");
		}elseif($_GET['type'] == 3){
			$job_list = $this->obj->DB_select_all("entry","`member_id`='".$member_id."' and `entry_state`=2 order by add_time desc");
		}
		if(!empty($job_list)){
			foreach($job_list as $k=>$v){
				$job_list[$k]['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
				$job_list[$k]['company_name'] = "投递 ".$v['company_name'];
			}
		}


		$this->yunset("user", $user);
		$this->yunset("job_list", $job_list);
		$this->yunset("type", $_GET['type']);


		$this->jingjiren_tpl("pin-yhrz_list");
	}
	/*
 	*用户投递详情
 	*/
	function entry_info_action(){
		$this->check();
		$id = $_GET['delivery_id'];
		$type = $_GET['type'];

		//查询投递信息
		$job = $this->obj->DB_select_once("entry","`id`=".$id);
		//查询个人信息   2019/4/16 替换跨库为java接口
//		$user=$this->objlan->DB_select_once("app_user","`user_id`=".$job['member_id'],"`user_id`,`username`,`user_avatar`,`realname`");
		$user = $this->getUser($job['member_id']);
		$job['add_time'] = date('Y-m-d H:i:s',$job['add_time']);
		$job['entry_time'] = date('Y-m-d',$job['entry_time']);
		$job['username'] = $user['username'];
		$job['user_avatar'] = $user['user_avatar'];
		$job['realname'] = $user['realname']?$user['realname']:'未设置真实姓名';




		$this->yunset("user", $user);
		$this->yunset("job", $job);
		$this->yunset("type", $type);
		$this->jingjiren_tpl("pin-yhrz_info");
	}

	/*
	 * 修改处理状态
	 * */
	function edit_entry_action(){
		$this->check();

		//查询投递信息
		$job = $this->obj->DB_select_once("entry","`id`=".$_GET['id']);

		$this->yunset("job", $job);
		$this->yunset("id", $_GET['id']);
		$this->yunset("user_id", $_GET['user_id']);
		$this->yunset("type", $_GET['type']);
		$this->jingjiren_tpl("pin-yhrz_infoedit");
	}
	/*
 	* 投递处理保存
 	*/
	function entry_save_action(){
		$this->check();
		$id = $_POST['id'];
		$agent_id = $_SESSION['user']['id'];
		//查询是否第一次入职
		$sum = 0;
		$sum = $this->obj->DB_select_num("entry"," `member_id`=".$_POST['member_id']." and `entry_state`=3");

		$where = " 1";
		$where .=" and `id`=".$_POST['id'];

		$data = "";
		$data .= "`handle_state` = 1,";
		//$data .= "`agent_id` =".$agent_id.",";
		$data .= "`entry_state` = ".$_POST['chuli'].",";
		$data .= "`entry_time` ='".strtotime($_POST['gather_data'])."',";
		$data .= "`edit_time` ='".time()."'";

		$uid = $this->obj->DB_update_all("entry",$data,$where);

		//是否第一次入职   2019/4/16 替换跨库为java接口
		$condition = array();
		$condition['userId'] = $_POST['member_id'];
		if($sum >= 1){
			$condition['agbId']="2";
		}else{
			$condition['agbId']="1";
		}
		//$condition.=['work_status'] = 3;
		$condition['inductionTime']=$_POST['gather_data'];
		$condition['work_status']="3";
		$aid = $this->yingpin_model->editBusinessOnce($data);
//		$aid=$this->objlan->DB_update_all("agent_business",$condition," `user_id`='".$_POST['member_id']."' and `enable`=1 ");
		//给王传入职人员状态
		$jobs = $this->obj->DB_select_once('entry','`id`='.$_POST['id']);
		if($_POST['chuli'] == '3') {
			if ($_POST['member_phone']) {
				$condition = array();
				$condition['isRecommendedMobile'] = $jobs['member_phone'];
				$condition['status'] = "3";
				$condition['statusValue'] = "已入职";
				$condition['companyId'] = $jobs['company_id'];
				$condition['entryTime'] = date('Y-m-d H:i:s') ;
//				$bid = $this->objlan->DB_update_all("app_recommend", $condition, " `is_recommended_mobile`='" . $jobs['member_phone'] . "'");
				$this->yingpin_model->editRecommendOnce($condition);
			}
		}
		//临时活动新加表（2019.2.25）===========================================================================start
		if($_POST['chuli'] == '3'){
			$activity_id = array('10053','10069','10084','10052','10063','10107','10118','10115');
			if(time()>=1551369600 && time() <= 1556640000 && in_array($jobs['company_id'],$activity_id)){
					$data = array();
					$data['userId'] = $_POST['member_id'];
					$data['realname'] = $jobs['member_name'];
					$data['mobile'] = $jobs['member_phone'];
					$data['idCard'] = $jobs['member_card'];
					$data['companyId'] = $jobs['company_id'];
					$data['companyName'] = $jobs['company_name'];
					$data['jobId'] = $jobs['job_id'];
					$data['type'] = 1;
					if($jobs['job_id']){
						$job_info = $this->obj->DB_select_once('company_job','`id`='.$jobs['job_id'],'id,name,company_id,com_name,salary_type');
						$data['jobName'] = $job_info['name'];
						$data['salaryType'] = $job_info['salary_type'];
					}

					$data['deliverTime'] = date('Y-m-d H:i:s',$jobs['add_time']);
					$data['username'] = $jobs['nickname'];

					if($jobs['member_phone']){
//						$is_recommend = $this->objlan->DB_select_once('app_recommend','`is_recommended_mobile`='.$jobs['member_phone']);//2019/4/16 替换跨库为java接口
						$is_recommend = $this->yingpin_model->getRecommendOnce($jobs['member_phone']);
						if(!empty($is_recommend)){
							$data['source'] = 1;
						}else{
							$data['source'] = 2;
						}

					}
					$data['entryTime'] = $_POST['gather_data'];
					$data['cost'] = '300';
					$data['createTime'] = date('Y-m-d H:i:s');
//					$aid=$this->objlan->insert_into('app_activity',$data);//2019/4/16 替换跨库为java接口
					$aid = $this->yingpin_model->addActivityOnce($data);
			}else{
				$data = array();
				$data['userId'] = $_POST['member_id'];
				$data['realname'] = $jobs['member_name'];
				$data['mobile'] = $jobs['member_phone'];
				$data['idCard'] = $jobs['member_card'];
				$data['companyId'] = $jobs['company_id'];
				$data['companyName'] = $jobs['company_name'];
				$data['jobId'] = $jobs['job_id'];
				$data['type'] = 2;
				if($jobs['job_id']){
					$job_info = $this->obj->DB_select_once('company_job','`id`='.$jobs['job_id'],'id,name,company_id,com_name,salary_type');
					$data['jobName'] = $job_info['name'];
					$data['salaryType'] = $job_info['salary_type'];
				}

				$data['deliverTime'] = date('Y-m-d H:i:s',$jobs['add_time']);
				$data['username'] = $jobs['nickname'];

//				if($jobs['member_phone']){
//					$is_recommend = $this->objlan->DB_select_once('app_recommend','`is_recommended_mobile`='.$jobs['member_phone']);
//					if(!empty($is_recommend)){
//						$data['source'] = 1;
//					}else{
						$data['source'] = 3;
//					}
//
//				}
				$data['entryTime'] = $_POST['gather_data'];
				$data['cost'] = '0';
				$data['createTime'] = date('Y-m-d H:i:s');
//				$aid=$this->objlan->insert_into('app_activity',$data);//2019/4/16 替换跨库为java接口
				$aid = $this->yingpin_model->addActivityOnce($data);
			}

		}
		//限时活动============================================================================================================end
		if($uid){
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=userentry'));die;
		}else{
			echo json_encode(array('msg'=>'保存失败！'));die();
		}


	}










	//统计模块
	/*
	 * 我的统计
	 * */
	function mystatistics_action(){
		$this->check();
		$agent_id = $_SESSION['user']['id'];
		//初始化时间
		$sdate = date("Y-01-01",time());
		$edate = date("Y-m-01", strtotime("+1 year", strtotime($sdate)));
		if($_GET['gather_data2']){
			$sdate = date("Y-m-01",strtotime($_GET['gather_data2']));
		}
		if($_GET['gather_data3']){
			$edate = date("Y-m-01",strtotime($_GET['gather_data3']));
		}
		//处理时间格式，转化成时间戳进行循环，来获得月份数组
		$cate  = array();
		$register = array();
		$stime = strtotime($sdate);
		$etime = strtotime($edate);
		while($stime<=$etime){
			$cate[] = "'".date("Y-m-01",$stime)."'" ;
			//获取注册人数   2019/4/16 替换跨库为java接口
			$stime1 =date("Y-m-01",$stime);
			$stime2 =date("Y-m-01", strtotime("+1months", $stime));
			$where = array();
			$where['agentId'] = $agent_id;
			$where['startTime'] = $stime1;
			$where['endTime'] = $stime2;
			$register[] = $this->yingpin_model->getBusinessNum($where);
//			$register[] = $this->objlan->DB_select_num("agent_business",$where);

			//获取结束
			$stime =strtotime(date("Y-m", strtotime("+1months", $stime)));
		}
		//查询有意向人数   2019/4/16 替换跨库为java接口
		$where = array();
		$where['agentId'] = $agent_id;
		$where['startTime'] = $sdate;
		$where['endTime'] = $edate;
		$usernum = $this->yingpin_model->getBusinessNum($where);
//		$usernum = $this->objlan->DB_select_num("agent_business",$where);
		$where = array();
		$where['agentId'] = $agent_id;
		$where['workStatus'] = '5';
		$where['startTime'] = $sdate;
		$where['endTime'] = $edate;
		$usernum_y = $this->yingpin_model->getBusinessNum($where);
		//$usernum = $this->objlan->DB_select_num("agent_business",$where);
//		$usernum_y = $this->dblan->DB_query_all("SELECT count(*) as num FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where,'all');
		//查询入职的统计
		$where = " 1";
		$where .= " and `agent_id`=".$agent_id;
		//$where .= " and `entry_state`=3";
		$where .= " and `add_time` BETWEEN '".strtotime($sdate)."' and '".strtotime($edate)."' ";
		$entry = $this->obj->DB_select_num("entry",$where);
		$where = " 1";
		$where .= " and `agent_id`=".$agent_id;
		$where .= " and `entry_state`=3";
		$where .= " and `add_time` BETWEEN '".strtotime($sdate)."' and '".strtotime($edate)."' ";
		$entry_y = $this->obj->DB_select_num("entry",$where);


		//注册人数所需数据
		$cates = implode(",", $cate);
		$max = ceil(max($register)/10)*10;
		$count = array_sum($register);
		$register = implode(",", $register);

		$this->yunset("register", $register);
		$this->yunset("cates", $cates);
		$this->yunset("count", $count);
		$this->yunset("max", $max);
		//有意向相关数据
		$this->yunset("usernum", $usernum);
		$this->yunset("usernum_y", $usernum_y);
		$this->yunset("usernum_n", $usernum-$usernum_y);
		//入职相关
		$this->yunset("entry", $entry-$entry_y);
		$this->yunset("entry_y", $entry_y);


		$this->yunset("gather_data2", $_GET['gather_data2']);
		$this->yunset("gather_data3", $_GET['gather_data3']);
		$this->jingjiren_tpl("pin-yhtj");
	}



	//佣金模块
	/*
	 * 我的佣金
	 * */
	function mycommission_action(){
		$this->check();
		$agent_id = $_SESSION['user']['id'];

		$stime = "";
		$etime = "";
		//处理条件
		if($_GET['gather_data1']){
			$stime = $_GET['gather_data1'];
			$etime = date("Y-m-d H:i:s", strtotime("+1months",strtotime($stime)));
		}else{
			//无查询时间搜索该经纪人的所有   //2019/4/16 替换跨库为java接口
			$where = array();
			$where['agent_id'] = $agent_id;
			$where['orderBy'] = "1";
			$min = $this->yingpin_model->getCommissionOnce($where);
//			$min= $this->objlan->DB_select_once("commission",$where);
			$stime = $min['dateTime'];

			$where = array();
			$where['agent_id'] = $agent_id;
			$where['orderBy'] = "2";
			$max = $this->yingpin_model->getCommissionOnce($where);
//			$max= $this->objlan->DB_select_once("commission",$where);
			$etime = $max['dateTime'];
		}
		//处理时间格式进行循环
		$sdate = date("Y-m-01",  strtotime($stime));
		$edate = date("Y-m-01", strtotime("+1months", strtotime($etime)));
		$stime = strtotime($sdate);
		$etime = strtotime($edate);
		$comm = array();
		while($stime<=$etime){
			//获取注册人数
			$stime1 =date("Y-m-01",$stime);
			$stime2 =date("Y-m-01", strtotime("+1months", $stime));
			$where = array();
			$where['agentId'] = $agent_id;
			$where['startTime'] = $stime1;
			$where['endTime'] = $stime2;
			$where['orderBy'] .= "2";
			$comm[] =$this->yingpin_model->getCommissionOnce($where);
//			$comm[] = $this->objlan->DB_select_once("commission",$where);
			//获取结束
			$stime =strtotime(date("Y-m", strtotime("+1months", $stime)));
		}



		$total = 0;
		if(!empty($comm)){
			foreach($comm as $k=>$v){
				if($v == false){
					unset($comm[$k]);
				}else{
					$total += $v['com_number'];
					$comm[$k]['date'] = date('Y-m',strtotime($v['dateTime']));
				}
			}
		}


		$this->yunset("gather_data1", $_GET['gather_data1']);
		$this->yunset("commission", $comm);
		$this->yunset("total", $total);
		$this->jingjiren_tpl("pin-wdyj");
	}


	//我的模块
	/*
	 * 个人信息
	 * */
	function myinfo_action(){
		$this->check();
		$agent_id = $_SESSION['user']['id'];
		//查询个人信息
		//$user = $this->objlan->DB_select_once("app_user","`user_id`=".$agent_id,"`user_id`,`username`,`user_avatar`,`sex_value`,`sex`");

		$this->yunset("user", $_SESSION['user']);
		$this->jingjiren_tpl("pin-mycenter");
	}
	/*
	 * 个人详细信息
	 * */
	function myinfo_detail_action(){
		$this->check();
		$agent_id = $_SESSION['user']['user_id'];;
		//查询个人信息   2019/4/16 替换跨库为java接口
		$user = $this->yingpin_model->getSysUserOnce(array('userId'=>$agent_id));
//		$user = $this->objlan->DB_select_once("sys_user","`user_id`=".$agent_id);
//		$agent = $this->objlan->DB_select_once("agent","`userInfo_id`=".$agent_id);
		$agent = $this->yingpin_model->getAgentOnce($agent_id);
		if(!$agent['wechatNumber']){
			$user['wechat_number'] = "暂无";
		}else{
			$user['wechat_number'] = $agent['wechatNumber'];
		}
		if(!$user['ossUrl']){
			$user['user_avatar'] = $_SESSION['user']['oss_url'];
		}else{
			$user['user_avatar'] = $user['ossUrl'];
		}

		$this->yunset("user", $user);
		$this->jingjiren_tpl("pin-mycenter_info");
	}

	/*
 	* 个人详细信息
 	*/
	function myinfo_save_action(){
		$this->check();
		$id = $_POST['id'];
		$agent_id = $_SESSION['user']['id'];


		$where = " 1";
		$where .=" and `user_id`=".$agent_id;

		$data = "";
		$data .= "`name` =".$_POST['username'].",";
		$data .= "`mobile` =".$_POST['mobile'].",";
		$data .= "`update_time` ='".strtotime($_POST['gather_data'])."'";

		$uid = $this->obj->DB_update_all("app_user",$data,$where);

		if($uid){
			echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=myinfo'));die;
		}else{
			echo json_encode(array('msg'=>'保存失败！'));die();
		}
	}

	/*
 	* 个人账号设置
 	*/
	function myinfo_set_action(){
		$this->check();
		$agent_id = $_SESSION['user']['user_id'];;
		//查询个人信息
//		$user = $this->objlan->DB_select_once("app_user","`user_id`=".$agent_id,"`user_id`,`username`,`user_avatar`,`sex_value`,`sex`,`sex_value`,`mobile`");
		$user = $this->getUser($agent_id);
		$this->yunset("user", $user);
		$this->jingjiren_tpl("pin-mycenter_pass");
	}
	/*
	 *	个人密码修改
	 */
	function myinfo_password_action(){
		$this->check();

		$id = $_POST['id'];
		$agent_id = $_SESSION['user']['user_id'];

//访问Java接口  地址随服务器更改--------------------------------------------------------------
		$url = "http://47.104.30.217:8080/lanlingwang/sys/user/phpPassword";
		$post_data = array ("password" => $_POST['passwordold'],"newPassword" => $_POST['password'],"userId"=>$agent_id);
		$ch = curl_init();

		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
		curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Content-Type: application/json',
			'Content-Length: ' . strlen(json_encode($post_data))
		));

		$output = curl_exec($ch);
		curl_close($ch);
		$output = json_decode($output,true);
		//接口访问结束------------------------------------------------------------------------------


		if($output['code'] == 0){
			//echo json_encode(array('url'=>$this->config['sy_weburl'].'/jingjiren/index.php?c=myinfo'));die;
			unset($_SESSION['user']);
			echo json_encode(array('msg'=>"修改成功，跳转登录页！",'url'=>$this->config['sy_weburl'].'/jingjiren/index.php?'));
			//echo json_encode(array('msg'=>"成功"));die();

			die();
		}else{
			echo json_encode(array('msg'=>$output['msg']));die();
		}

	}

//	function test_action(){
//		$url = "http://192.168.11.228:8080/lanling/sys/phpLogin";
//		$post_data = array ("username" => "111","password" => "111");
//		$ch = curl_init();
//
//		curl_setopt($ch, CURLOPT_URL, $url);
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//// post数据
//		curl_setopt($ch, CURLOPT_POST, 1);
//// post的变量
//		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
//		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
//			'Content-Type: application/json',
//			'Content-Length: ' . strlen(json_encode($post_data))
//		));
//
//		$output = curl_exec($ch);
//		curl_close($ch);
//		$output = json_decode($output,true);
//		var_dump($output);die;
//
//	}
	/*
	 * 通知
	 */
	function mynews_action(){
		$this->check();
		$agent_id = $_SESSION['user']['user_id'];
		//查询经纪人的个人消息列表

//		$msg0 = $this->objlan->DB_select_all("agent_message","`agent_id`=".$agent_id." and `is_see`=0 order by `mes_time` desc");
//		$msg1 = $this->objlan->DB_select_all("agent_message","`agent_id`=".$agent_id." and `is_see`=1 order by `mes_time` desc");
		$msg0 = $this->yingpin_model->getMessageAll(array('agentId'=>$agent_id,'isSee'=>'0'));
		$msg1 = $this->yingpin_model->getMessageAll(array('agentId'=>$agent_id,'isSee'=>'1'));

		$this->yunset("msg0", $msg0);
		$this->yunset("msg1", $msg1);
		$this->jingjiren_tpl("pin-message");
	}
	/*
	 * 通知详情
	 */
	function mynews_detail_action(){
		$this->check();

		if($_GET['msg_id']){
			$where = array();
			$where['id'] = $_GET['msg_id'];
			$where['isSee'] ="1";
			$where['seeTime'] =date('Y-m-d H:i:s',time());
//			$uid = $this->objlan->DB_update_all("agent_message",$data,$where);
			$uid = $this->yingpin_model->editMessage($where);
		}


//		$msg = $this->objlan->DB_select_once("agent_message","`id`=".$_GET['msg_id']);//2019/4/16 替换跨库为java接口
		$msg = $this->yingpin_model->getMessageOnce($_GET['msg_id']);
		$weekarray=array("日","一","二","三","四","五","六");
		if($msg['mes_time']){
			$msg['week'] = "星期".$weekarray[date("w",strtotime($msg['mes_time']))];
		}
		$this->yunset("msg", $msg);
		$this->jingjiren_tpl("pin-message_detial");
	}

//	//用户入职模块
//	function userentry1_action(){
//		//qqqqqqqqqqqqqqqqqqqq
//		$this->check();
//		$user_id = $_SESSION['user']['id'];
//		$this->yunset("type", $_GET['type']);
//		//分页处理
//		$limit = 10;
//		$page = 0;
////		if($_GET['page']){
////			$page = ($_GET['page']-1)*$limit;
////		}
//		//$this->yunset("page", $_GET['page']);
//
//		//处理搜索条件
//		$where = " 1";
//		if($_GET['keyword'] && $_GET['keyword']!='undefined'){
//			$where .=" and  CONCAT(`username`,`mobile`) like '%".trim($_GET['keyword'])."%'";
//		}
//		$filed = "`agent_id`,a.`user_id`,`username`,`mobile`,`realname`,b.`work_status`,`user_avatar`,a.`create_time`";
//		if($_GET['type'] == 1){
//			if($_GET['page1']){
//				$page = ($_GET['page1']-1)*$limit;
//			}
//			//为處理
//			$no_contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC limit ".$page.",".$limit,'all');
//			foreach($no_contact as $k=>$v){
//				if($v['work_status'] == 5){
//					$no_contact[$k]['work_status'] = '找工作中';
//				}elseif($v['work_status'] == 6){
//					$no_contact[$k]['work_status'] = '已找到工作';
//				}else{
//					$no_contact[$k]['work_status'] = '未知状态';
//				}
//				$no_contact[$k]['page1'] = $_GET['page1'];
//			}
//			echo json_encode($no_contact);die();
//		}elseif($_GET['type'] == 2){
//			if($_GET['page2']){
//				$page = ($_GET['page2']-1)*$limit;
//			}
//			//已處理ll
//			$contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=1 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC limit ".$page.",".$limit,'all');
//			foreach($contact as $k=>$v){
//				if($v['work_status'] == 5){
//					$contact[$k]['work_status'] = '找工作中';
//				}elseif($v['work_status'] == 6){
//					$contact[$k]['work_status'] = '已找到工作';
//				}else{
//					$contact[$k]['work_status'] = '未知状态';
//				}
//				$contact[$k]['page2'] = $_GET['page2'];
//			}
//			echo json_encode($contact);die();
//		}
//
////		$this->yunset("keyword", $_GET['keyword']);
////		$this->yunset("no_contact", $no_contact);
////		$this->yunset("contact", $contact);
////
////		$this->jingjiren_tpl("pin-wdkh");
//	}
	//用户入职模块
	function userentry1_action(){
		//qqqqqqqqqqqqqqqqqqqq
		$this->check();
		$user_id = $_SESSION['user']['id'];
		$this->yunset("type", $_GET['type']);
		//分页处理
		$limit = 10;
		$page = 0;
		//处理搜索条件
		$where = array();
		if($_GET['keyword'] && $_GET['keyword']!='undefined'){
			$where['searchValue'] .= trim($_GET['keyword']);
		}
//		$filed = "`agent_id`,a.`user_id`,`username`,`mobile`,`realname`,b.`work_status`,`user_avatar`,a.`create_time`";
		if($_GET['type'] == 1){
//			if($_GET['page1']){
//				$page = ($_GET['page1']-1)*$limit;
//			}
			//为處理
			$where['contact'] = '0';
			$where['agentId'] = $user_id;
			$where['page'] = $_GET['page1'];
			$no_contact = $this->yingpin_model->getBusinessUserPage($where);
//			$no_contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC limit ".$page.",".$limit,'all');
			foreach($no_contact as $k=>$v){
				$no_contact[$k]['agent_id'] = $v['agentId'];
				$no_contact[$k]['user_id'] = $v['userId'];
				$no_contact[$k]['user_avatar'] = $v['userAvatar'];
				$no_contact[$k]['work_status'] = $v['workStatus'];
				$no_contact[$k]['create_time'] = $v['createTime'];
				if($v['workStatus'] == 5){
					$no_contact[$k]['work_status'] = '找工作中';
				}elseif($v['workStatus'] == 6){
					$no_contact[$k]['work_status'] = '已找到工作';
				}else{
					$no_contact[$k]['work_status'] = '未知状态';
				}
				$no_contact[$k]['page1'] = $_GET['page1'];
			}
			echo json_encode($no_contact);die();
		}elseif($_GET['type'] == 2){
//			if($_GET['page2']){
//				$page = ($_GET['page2']-1)*$limit;
//			}
			//已處理ll
			$where['contact'] = '1';
			$where['agentId'] = $user_id;
			$where['page'] = $_GET['page2'];
			$contact = $this->yingpin_model->getBusinessUserPage($where);
//			$contact = $this->dblan->DB_query_all("SELECT ".$filed." FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.`user_id` WHERE".$where." and a.`contact`=1 and a.`agent_id`=".$user_id." ORDER BY a.`create_time` DESC limit ".$page.",".$limit,'all');
			foreach($contact as $k=>$v){
				$contact[$k]['agent_id'] = $v['agentId'];
				$contact[$k]['user_id'] = $v['userId'];
				$contact[$k]['user_avatar'] = $v['userAvatar'];
				$contact[$k]['work_status'] = $v['workStatus'];
				$contact[$k]['create_time'] = $v['createTime'];
				if($v['workStatus'] == 5){
					$contact[$k]['work_status'] = '找工作中';
				}elseif($v['workStatus'] == 6){
					$contact[$k]['work_status'] = '已找到工作';
				}else{
					$contact[$k]['work_status'] = '未知状态';
				}
				$contact[$k]['page2'] = $_GET['page2'];
			}
			echo json_encode($contact);die();
		}

	}
	//用户投递模块
	function userentry2_action(){
		//qqqqqqqqqqqqqqqqqqqq
		$this->check();
		$user_id = $_SESSION['user']['id'];
		$this->yunset("type", $_GET['type']);
		//分页处理
		$limit = 10;
		$page = 0;
		//处理搜索条件
		$where = " 1";
		if($_GET['keyword'] && $_GET['keyword']!='undefined'){
			$where .=" and  CONCAT(`nickname`,`member_phone`) like '%".trim($_GET['keyword'])."%'";
		}
		$filed = "`id`,`agent_id`,`member_id` as user_id,`nickname` as username,`member_phone` as mobile,`member_name` as realname,`entry_state`,`user_avatar`,`add_time`,`company_name`";
		if($_GET['type'] == 1){
			if($_GET['page1']){
				$page = ($_GET['page1']-1)*$limit;
			}
			$where .= " and `agent_id`=".$user_id;
			$where .= " and `handle_state`=0";
			//为處理
			$no_contact = $this->obj->DB_query_all("SELECT ".$filed." FROM phpyun_entry WHERE".$where." group by `member_id` ORDER BY `add_time` DESC limit ".$page.",".$limit,'all');
			foreach($no_contact as $k=>$v){
				$no_contact[$k] = $v;
				$no_contact[$k]['toudi_id'] =  $v['id'];
				$no_contact[$k]['add_time'] =date('Y-m-d H:i:s',$v['add_time']);
				$no_contact[$k]['company_name'] = "投递 ".$v['company_name'];
				$no_contact[$k]['page1'] = $_GET['page1'];
			}
			echo json_encode($no_contact);die();
		}elseif($_GET['type'] == 2){
			if($_GET['page2']){
				$page = ($_GET['page2']-1)*$limit;
			}
			//已處理ll
			$where .= " and `agent_id`=".$user_id;
			$where .= " and `handle_state`=1";
			$contact = $this->obj->DB_query_all("SELECT ".$filed." FROM phpyun_entry WHERE".$where." ORDER BY `add_time` DESC limit ".$page.",".$limit,'all');
			foreach($contact as $k=>$v){
				$contact[$k] = $v;
				$contact[$k]['toudi_id'] =  $v['id'];
				$contact[$k]['add_time'] =date('Y-m-d H:i:s',$v['add_time']);
				$contact[$k]['company_name'] = "投递 ".$v['company_name'];
				$contact[$k]['page2'] = $_GET['page2'];
			}
			echo json_encode($contact);die();
		}

	}
	function test_action(){
		$model = $this->MODEL('yingpin');
		//$res = $model->getUser('98');//获取用户信息
//		$res = $model->getCompany();//获取全部企业信息
		//$res = $model->getCompanyOnce('10050');//获取单条企业信息
		//$res = $model->getBusinessOnce('61');//获取单条经纪人信息

		$data = array();
		//修改agent_business表数据
//		$data['userId'] = '63';
//		$data['agbId'] = '1';
//		$data['inductionTime'] = '2019-04-15 13:55:11';
//		$data['workStatus'] = '3';

//		$data['agentId'] = '22';
//		$data['userId'] = '19127';
//		$data['handleState'] = '1';
//		$data['handleMsg'] = '已处理，等袋中';
//		$data['handleTime'] = '2019-04-15 13:55:11';
//		$data['contact'] = '1';
//		$data['updateTime'] = '2019-04-15 13:55:11';
//
//		$res = $model->editBusinessOnce($data);

		//用户入职修改app_recommend表
//		$data['isRecommendedMobile'] = '15954270756';
//		$data['status'] = '3';
//		$data['statusValue'] = '已入职';
//		$data['companyId'] = '10118';
//		$data['entryTime'] = '2019-04-15 13:55:11';
//		$res = $model->editRecommendOnce($data);

		//$res = $model->getRecommendOnce('15954270756');//查询app_recommend，获取用户是否是被推荐用户

		//新增app_activity活动表数据
//		$data['userId'] = '1339';
//		$data['username'] = '用户_二狗子';
//		$data['realname'] = '111';
//		$data['mobile'] = '17864273007';
//		$data['idCard'] = '123456789987654321';
//		$data['companyId'] = '10062';
//		$data['companyName'] = '顺丰速运青岛分公司';
//		$data['jobId'] = '150';
//		$data['jobName'] = '普工';
//		$data['source'] = '3';
//		$data['entryTime'] = '2019-02-20 00:00:00';
//		$data['cost'] = '100';
//		$data['salaryType'] = '3';
//		$data['deliverTime'] = '2019-04-15 13:55:11';
//		$data['createTime'] = '2019-04-15 13:55:11';
//		$data['type'] = '2';
//		$res = $model->addActivityOnce($data);


		//$res = $model->getUserRealname('18');//查询app_recommend，获取用户是否是被推荐用户

		//jobadd修改候选人的状态
//		$data['userId'] = '66';
//		$data['workStatus'] = '2';
//		$res = $model->editBusinessOnce($data);

		//$res = $model->getCompanyImage('10100');//获取企业的图片

		//插入投递日志
//		$data['title'] = '您的简历已投递';
//		$data['details'] = '您的简历投递失败，该职位已下架';
//		$data['userId'] = '13682';
//		$data['createTime'] = '2019-04-15 13:55:11';
//		$data['msgType'] = '1';
//		$data['status'] = '0';
//		$res = $model->addMessageLog($data);

		//签到回调天数增添
//		$data['userId'] = '61';
//		$data['signday'] = '11';
//		$data['signdays'] = '12';
//		$res = $model->editUserSigndays($data);

		//查询sys_user单条信息
//		$data['username'] = 'sunyawen';
//		$data['userId'] = '144';
//		$res = $model->getSysUserOnce($data);

		//查询agent表，获取经纪人相关信息
		//$res = $model->getAgentOnce('150');

		//查询agent_business所有数据
		//$res = $model->getBusinessAll('18');

		//查询agent_business数量
//		$data['agentId'] = '22';
//		$data['contact'] = '1';
//		$data['searchValue'] = '';
//		$res = $model->getBusinessNum($data);
////		$data['startTime'] = '2019-04-11 15:49:40';
////		$data['endTime'] = '2019-04-14 13:43:01';
//		$res = $model->getBusinessNum($data);
//		if($_GET['keyword']){
//			$where .=" and  CONCAT(`username`,`mobile`) like '%".trim($_GET['keyword'])."%'";
//		}
//		$no_sql = "SELECT count(*) as num FROM agent_business a LEFT JOIN app_user b ON a.`user_id`=b.user_id WHERE".$where." and a.`contact`=0 and a.`agent_id`=".$user_id;
//		$no_num=$this->dblan->DB_query_all($no_sql);

		//查询agent_message，查询经纪人变更记录
//		$data['agentId'] = '152';
//		$data['isSee'] = '0';
//		$res = $model->getMessageAll($data);

		//查询agent_trunk追踪记录
//		$data['agentId'] = '21';
//		$data['memberId'] = '168';
//		$res = $model->getTrackAll($data);

		//新增agent_trunk追踪记录
//		$data['agentId'] = '99';
//		$data['memberId'] = '9999';
//		$data['trackContent'] = '哈哈哈哈哈哈哈嗝';
//		$data['trackTime'] = '2019-04-14 13:43:01';
//		$res = $model->addTrackOnce($data);

		//查询commission表，查询经纪人佣金
//		$data['agentId'] = '152';
//		$data['startTime'] = '2018-12-31 00:00:00';
//		$data['endTime'] = '2019-02-01 00:00:01';
//		$data['orderBy'] = '2';
//		//$res = $model->getCommissionOnce($data);
//		$res = $model->getCommissionAll($data);

		//修改agent_message表单条信息
//		$data['id'] = '4';
//		$data['isSee'] = '1';
//		$data['seeTime'] = '2019-02-01 00:00:01';
//		$res = $model->editMessage($data);

		//查询agent_message表单条信息
//		$res = $model->getMessageOnce('5');
//		$res = $this->getUser('61');

		//19497
		$data['userId'] = '19497';
		$res = $model->getBusinessUserOnce($data);




		var_dump($res);
	}

}
?>